package cc.liyinghao.springsecuritydemo.security.config;


import cc.liyinghao.springsecuritydemo.security.component.RestAuthenticationEntryPoint;
import cc.liyinghao.springsecuritydemo.security.component.RestfulAccessDeniedHandler;
import cc.liyinghao.springsecuritydemo.security.util.JwtTokenUtil;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * SpringSecurity 通用bean注入配置
 */
@Configuration
public class CommonSecurityConfig {

    /**
     * jwt token 工具类注入
     */
    @Bean
    public JwtTokenUtil jwtTokenUtil() {
        return new JwtTokenUtil();
    }

    /**
     * 忽略url配置注入
     */
    @Bean
    public IgnoreUrlsConfig ignoreUrlsConfig() {
        return new IgnoreUrlsConfig();
    }

    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }

    @Bean
    public RestfulAccessDeniedHandler restfulAccessDeniedHandler() {
        return new RestfulAccessDeniedHandler();
    }

    @Bean
    public RestAuthenticationEntryPoint restAuthenticationEntryPoint() {
        return new RestAuthenticationEntryPoint();
    }

}
